import datetime


class MessageModel:
    def __init__(self, sender, msg):
        self.sender = sender
        # self.receiver = receiver
        self.send_time = datetime.datetime.now()
        self.msg = msg

    def jsonfy(self) -> dict:
        json_obj = dict(
            sender=self.sender,
            message=self.msg,
            send_time=self.send_time,
        )
        return json_obj


class MsgInfoModel:
    def __init__(self, msg):
        """取出msg内存在的信息"""
        if hasattr(msg.User, 'NickName'):
            self.room_name = msg.User.NickName  # 群聊名称
        else:
            self.room_name = '未命名群组'

        if hasattr(msg, 'Text'):
            self.text = msg.Text  # 文字消息
        else:
            self.text = ''

        self.from_user_name = msg.FromUserName  # 可能是群聊名，也可能是个人名称的username
        if hasattr(msg, 'ActualNickName'):
            self.nick_name = msg.ActualNickName  # 群聊时的个人名称

        self.msg = msg
